package v2

import (
	rpcv1 "gluenet/internal/agent/api/rpc/v1"
	corev1 "gluenet/pkg/agent/types"
	"gluenet/pkg/agent/v2/rpc"
)

type JaegerGetter interface {
	Jaeger() GluenetJaegerInterface
}

type GluenetJaegerInterface interface {
	JaegerService(jaegerServiceReq *corev1.JaegerService) (result []byte, err error)
	JaegerOperate(jaegerOperateReq *corev1.JaegerOperate) (result []byte, err error)
	JaegerTraces(jaegerTracesReq *corev1.JaegerTraces) (result []byte, err error)
}

type gluenetJaeger struct {
	client rpc.Interface
}

func newGluenetJaeger(c *CoreClient) *gluenetJaeger {
	return &gluenetJaeger{
		client: c.RPCClient(),
	}
}

func (c *gluenetJaeger) JaegerService(jaegerServiceReq *corev1.JaegerService) (result []byte, err error) {
	err = c.client.Invoke().
		Api(rpcv1.JaegerService).
		Spec(*jaegerServiceReq).
		Do().
		Into(&result)
	return
}

func (c *gluenetJaeger) JaegerOperate(jaegerOperateReq *corev1.JaegerOperate) (result []byte, err error) {
	err = c.client.Invoke().
		Api(rpcv1.JaegerOperate).
		Spec(*jaegerOperateReq).
		Do().
		Into(&result)
	return
}

func (c *gluenetJaeger) JaegerTraces(jaegerTracesReq *corev1.JaegerTraces) (result []byte, err error) {
	err = c.client.Invoke().
		Api(rpcv1.JaegerTraces).
		Spec(*jaegerTracesReq).
		Do().
		Into(&result)
	return
}
